package cn.cqsztech.mq.active.util;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.ActiveMQTopic;

import javax.jms.JMSException;
import javax.jms.TextMessage;

/**
 * ccmars
 * 2022/3/4
 **/
public class TopicPublisher {
    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            publish("name", "name" + i);
        }
    }

    public static void publish(String topicName, String message) {
        ActiveMQTopic topic = new ActiveMQTopic(topicName);
        TextMessage m = new ActiveMQTextMessage();
        try {
            m.setText(message);
        } catch (JMSException e) {
            e.printStackTrace();
        }
        ActiveMQUtil.publish(topic, m);
    }
}
